package com.zwz.crawler.knowledge;

import com.zwz.parse.JsonParserUtil;
import lombok.extern.slf4j.Slf4j;
import org.jsoup.Connection;
import org.jsoup.Jsoup;

import java.io.UncheckedIOException;

/**
 * 数据读取对应的知识产权信息
 */
@Slf4j
public class TungKnowledgePatent {

    String url = "https://sales.tungee.com/api/enterprise/577de19eadf21dc4/intellectual-property/patent?start=0&end=5";


        public static void startTungKnowledgePatent( ) {
            String url = "https://sales.tungee.com/api/enterprise/577de19eadf21dc4/intellectual-property/patent";
            String cookie = "_tx_pid=67864ea75f69e05d3b544ca7; __wpkreporterwid_=cc4a07fc-7bb9-40a4-96bc-2cbac34b658f; __last_enter_version=sales; _co_i=6805a5576eceb9637696f09d; _tx_uid=680701dddca941522b77e864; _tx_cid=6805a5576eceb9637696f09d; DISTINCT_ID=b84fe276-099f-4932-92b3-d54b92ae384b; _tx_sid=MTc0NTMwMTE0MzYyMjo4MmQ2OTQ5MTY0NjU2ODNmYjQ5MjlmMjc3NDg5ZDFlZg==; Hm_lvt_f2ee75449fc055cc4dbceb4fe403bea3=1745301094,1745302709; HMACCOUNT=B4E402DF057C895E; SecurityCenterDuId=ImFBSG15RzdPdVdPdCtsWnNGMFVuSXhVPSI.GujnjA.YBo4Zvc8vs4jgEmtioacknOQ9pE; tg_referrer_source=https%3A%2F%2Fuser.tungee.com%2F; Hm_lpvt_f2ee75449fc055cc4dbceb4fe403bea3=1745311256; acw_tc=1a0c399c17453755117888163e00750937494c94d4c1dcf8613007f6c82701; accountCenterSessionId=.eJwlj0FLxDAQRv9LznuYyUyT7N7ULl7c9rIi9FImyYRaSoW2q6L43y16_h6P932b_jWbkyGhUAJiBKXsKBcswaFi1qixePRKEpKNGVhYmVNK3gsBWJAERwDwJVAOgUUYyUeSIlXybFMFJDFzBRmjAw5gHWNmtWCL0m7OntQcTF8WXQdz2pabHkwaZJ512tM-NO7rrJr7Vd613976HM2pyLTu3PqX39bD0Hwl7Ornra27oXsAaK_N-PRy_mweL1sz3lWXazc19Zm68X7YhbdVl__vLoCvHCSnSePRUVRGtNaan1-L6FR_.GunkUg.BGKgr1CKO3fsJWE1RtkS48ULZ-w; doncusSessionId=eyJfZnJlc2giOmZhbHNlLCJ1c2VyX2lkIjoiNjgwNzAxZGRkY2E5NDE1MjJiNzdlODY0In0.GunkYA.Z21I5p_aMC1T41Qe1YguHNadGuE"; // 完整 Cookie

            try {
                // 构建带参数的 URL（GET 请求参数直接拼接）
                String fullUrl = url + "?start=0&end=5";

                // 发送请求（模拟 HTTP/2 伪头）
                Connection.Response response = Jsoup.connect(fullUrl)
                        .method(Connection.Method.GET)
                        .ignoreContentType(true)  // 允许非 HTML 响应
                        .timeout(30_000)
                        // 伪头映射（Jsoup 不支持冒号头，转换为普通头）
                        .header("authority", "sales.tungee.com")
                        .header("path", "/api/enterprise/577de19eadf21dc4/intellectual-property/patent?start=0&end=5")
                        // 标准请求头
                        .header("accept", "*/*")
                        .header("accept-encoding", "gzip, deflate, br, zstd")
                        .header("accept-language", "zh-CN,zh;q=0.9")
                        .header("cache-control", "no-cache")
                        .header("cookie", cookie)
                        .header("pragma", "no-cache")
                        .header("priority", "u=1, i")
                        .header("referer", "https://sales.tungee.com/enterprise-details/577de19eadf21dc4/enterprise-information/intellectual-property")
                        .header("sec-ch-ua", "\"Not;A=Brand\";v=\"24\", \"Chromium\";v=\"128\"")
                        .header("sec-ch-ua-mobile", "?0")
                        .header("sec-ch-ua-platform", "\"Windows\"")
                        .header("sec-fetch-dest", "empty")
                        .header("sec-fetch-mode", "cors")
                        .header("sec-fetch-site", "same-origin")
                        .header("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/128.0.0.0 Safari/537.36")
                        .header("x-tonxis-pid", "67864ea75f69e05d3b544ca7")
                        .execute();

                // 输出结果
               log.info("状态码: " + response.statusCode());
//               log.info("响应内容: " + response.body());


                //解析
                JsonParserUtil.parsePatent(response.body());


            } catch (UncheckedIOException | java.io.IOException e) {
                e.printStackTrace();
            }
        }
    }




